This means, for instance, that you can bind to variables from the application or session object because the WOComponent class declares two instance variables, application and session, which point to the current application and the current session. For example, you might define a component that displays relevant information about the application, including the date and time the application was started. It makes sense for the application object to store this date and time. Your component's .wod file would access it through this declaration:
UP_SINCE:WOString {value = application.upSince.description};To retrieve a value from this binding, WebObjects uses key-value coding, a standard interface for accessing an object's properties either through methods designed for that purpose or directly through its instance variables. With key-value coding, WebObjects sends the same message (takeValue:forKey:, or takeValueForKey in Java) to any object it is trying to access. Key-value coding first attempts to access properties through accessor methods based on the key's name.
For example, to resolve the binding for the WOString element in the above component using key-value coding, WebObjects performs the following steps:
In this case, WOComponent defines the application method, which returns the WOApplication object.
If the method is not found, it looks for an upSince instance variable. In this case, the upSince instance variable is defined in the application's code file.
Because upSince is a date object, it defines a description method, which prints the object's value as a string.
For example, dictionary objects store key-value pairs. Suppose you declare a person dictionary that has the keys name, address, and phone. These keys aren't really instance variables in the dictionary, but because WebObjects accesses values using
key-value coding, the following binding works:
myString : WOString { value = person.name };
Enterprise objects also define keys, so the same binding would work if person was an enterprise object.
Even if your entire application is written in Java, you must use the Objective-C names for methods and for literals. For example, you must use YES instead of true, NO instead of false, and description instead of toString.
Table of Contents
Next Section